package com.ssmk.utlis;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.ssmk.R;

/**
 * Created by Administrator on 2017/9/7 0007.
 */

public class PopUtils {
    public static View getPopView(Context context){
        View view = LayoutInflater.from(context).inflate(R.layout.order_pay_popup, null);
        return view;
    }
    public static View getPopViewCancel(Context context){
        View view = LayoutInflater.from(context).inflate(R.layout.order_cancel_popup, null);
        return view;
    }
    public static PopupWindow getPopUpWindow(View view){
        PopupWindow popWin2 = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        return popWin2;
    }
    public static Activity showPop(Context context,View v,PopupWindow pop){
        final Activity mActivity = (Activity)context;
        //设置点击空白处消失
        pop.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
        pop.setTouchable(true);
        pop.setOutsideTouchable(true);
        // 设置背景颜色变暗
        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
        lp.alpha = 0.4f;
        mActivity.getWindow().setAttributes(lp);
        pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1f;
                mActivity.getWindow().setAttributes(lp);
            }
        });
        pop.showAtLocation(v, Gravity.BOTTOM, 0, 0);
        return mActivity;
    }
}
